package com.atguigu.gmall.cart.service;

import com.atguigu.gmall.cart.mapper.CartMapper;
import com.atguigu.gmall.cart.pojo.Cart;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
public class CartAsyncService {
    @Autowired
    CartMapper cartMapper;
    @Async
    public void update(String userId,Cart cart,String skuId){
        this.cartMapper.update(cart, new UpdateWrapper<Cart>().eq("user_id", userId).eq("sku_id", skuId));
    }
    @Async
    public void insert(String userId,Cart cart){
//        int i = 1 /0 ;
        this.cartMapper.insert(cart);
    }
    @Async
    public void delete(String userId) {
        this.cartMapper.delete(new QueryWrapper<Cart>().eq("user_id",userId));
    }

    public void deleteBySkuId(String userId, Long skuId) {
        this.cartMapper.delete(new QueryWrapper<Cart>().eq("user_id",userId).eq("sku_id",skuId));
    }
}
